package com.wms.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wms.bean.PageBean;
import com.wms.code.CodeFactory;
import com.wms.dto.AllocateSaveVo;
import com.wms.dto.AllocatedetailVo;
import com.wms.dto.AuditAllocateDTO;
import com.wms.entity.Allocate;
import com.wms.mapper.AllocateMapper;
import com.wms.service.AllocateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class AllocateServiceImpl implements AllocateService {
    @Autowired
    AllocateMapper allocateMapper;
    String prefix = "TF"; // 可以更改为不同的前缀

    // 创建新的到货单编码

    @Override
    public PageBean<List<Allocate>> query(AllocatedetailVo allocatedetailVo) {
       //设置分页参数
        PageHelper.startPage(allocatedetailVo.getPage(),allocatedetailVo.getPageSize());
        List<Allocate> list = allocateMapper.select(allocatedetailVo);
        PageInfo<Allocate> allocatePageInfo = new PageInfo<>(list);
        return new PageBean<List<Allocate>>(allocatedetailVo.getPage(),allocatedetailVo.getPageSize(),allocatePageInfo.getTotal(),allocatePageInfo.getList());
    }


    /**
     * 逻辑删除
     * @param id
     * @return
     */
    @Override
    public int remove(int id) {
        return allocateMapper.updateStatus(id);
    }


    /**
     * 新增调度单
     */
    @Override
    public int save(AllocateSaveVo allocateSaveVo) {
            //查询目前最大的编码
            String maxCode = allocateMapper.selectMaxCode();
            allocateSaveVo.setCode(CodeFactory.createArrivalCode(maxCode,prefix));
            return allocateMapper.insert(allocateSaveVo);
    }

    /**
     * 物理删除
     * @param id
     * @return
     */
    @Override
    public int removePhysics(int id) {
        return allocateMapper.deleteById(id);
    }


    /**
     * 更新调度单
     * @param allocateSaveVo
     * @return
     */
    @Override
    public int updateAllocateById(AllocateSaveVo allocateSaveVo) {
        return allocateMapper.updateAllocateById(allocateSaveVo);
    }


    @Override
    public List<Allocate> selectAll() {
        return allocateMapper.selectAll();
    }


    @Override
    public List<String> selectWarehouse() {
        return allocateMapper.selectWarehouse();
    }
}
